﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RepositoryFramework;
using Portal.Model;
using Portal.Models.SkillsCatalog;

namespace Portal.Repository.SkillsCatalog
{
	/// <summary>
	/// Class <see cref="CurriculumVitaeRepository"/> declare repository of CurriculumVitae
	/// </summary>
	public class CurriculumVitaeRepository : GenericRepository<SkillsCatalogEntities, CurriculumVitae>, ICurriculumVitaeRepository
	{
		#region .ctor

		/// <summary>
		/// Class <see cref="CurriculumVitaeRepository"/> constructor
		/// </summary>
		/// <param name="entities"></param>
		public CurriculumVitaeRepository(SkillsCatalogEntities entities)
			: base(entities)
		{

		}

		#endregion .ctor

		#region Methods
		/// <summary>
		/// Gets the cv by user.
		/// </summary>
		/// <param name="userId">The user identifier.</param>
		/// <returns>
		/// CV
		/// </returns>
		public ICurriculumVitae GetByUser(int userId)
		{
			var result = Get(cv => cv.UserId == userId).FirstOrDefault();
			return result;
		}

		/// <summary>
		/// Gets the cv preview by user.
		/// </summary>
		/// <param name="userId">The user identifier.</param>
		/// <returns>CV preview</returns>
		public ICurriculumVitaePreview GetPreviewByUser(int userId)
		{
			var result = Get(cv => cv.UserId == userId, includeProperties: "Employer").FirstOrDefault();
			return result;
		}
		#endregion
	}
}
